/*
 * @Author: libo
 * @Date: 2024-03-30 15:30:02
 * @LastEditors: libo
 * @LastEditTime: 2024-07-22 15:26:43
 * @FilePath: \all-blog-master\blog-server\controller\system\upload-controller.js
 * @Description: 
 * 
 */
const db = require('../../models/index');
const logger = require('../../utils/logger-util');
const { baseURL } = require('../../config/multer-config');
const DAO = require('../../dao/sql-option-dao');
const Users = db.users;
const Comments = db.comments;
const Danmu = db.danmu;
const Article = db.article;

// ========================= 更新用户头像 =========================
exports.updateAvatar = (async (req, res) => {
    try {
        const updateInfo = req.body;
        const userpicUrl = req.file.path.substring(req.file.path.lastIndexOf('u'));
        await Users.update({ avatar: userpicUrl }, { where:{ id: updateInfo.id }});
        // await Comments.update({ fromAvatar: userpicUrl}, { where:{ userId: updateInfo.id }});
        // await Danmu.update({ avatar: userpicUrl}, { where:{ userId: updateInfo.id }});
        res.sendResultAto(userpicUrl, 200, '更新成功');
    } catch (e) {
        console.log(e);
        logger.error(e);
        res.sendResultAto(null, 500, '服务器错误，请联系管理员！');
    }
});